{include file="layout/layout"}
<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表"><i class="fa fa-arrow-circle-o-left"></i></a>
            <div class="subject">
                <h3>代理管理 - 添加代理</h3>
                <h5>网站系统添加代理</h5>
            </div>
        </div>
    </div>
    <form class="form-horizontal" method="post" id="add_form" action="{:url('admin/agents/addDo')}">
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="nickname"><em>*</em>代理账户</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="age_username" id="nickname" class="input-txt">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="password"><em>*</em>登录密码</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="age_password" id="password" class="input-txt">
                    <span class="err"></span>
                    <p class="notic">6-16位字母数字符号组合</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="nickname22"><em>*</em>代理上限</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="agem_shop_max" id="nickname22" class="input-txt">
                    <span class="err"></span>
                    <p class="notic">代理商可代理商户的最大值</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="nickname22"><em>*</em>代理负责人姓名</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="agem_principals" id="nickname22" class="input-txt">
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="mobile"><em>*</em>手机号码</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="agem_phone" id="mobile" class="input-txt">
                    <span class="err"></span>
                    <p class="notic">前台登陆账号，手机邮箱任意一项都可以</p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="email"><em>*</em>邮件地址</label>
                </dt>
                <dd class="opt">
                    <input type="text" name="agem_email" id="email" class="input-txt">
                    <span class="err"></span>
                    <p class="notic">前台登陆账号，手机邮箱任意一项都可以</p>
                </dd>
            </dl>

            <dl class="row">
                <dt class="tit">
                    <label for="consignee"><em>*</em>地址</label>
                </dt>
                <dd class="opt">
                    <select onchange="get_city(this)" id="province" name="province" title="请选择所在省份">
                        <option value="">选择省份</option>
                        {volist name="province" id="pv"}
                        <option value="{$pv['id']}">{$pv['name']}</option>
                        {/volist}
                    </select>
                    <select onchange="get_area(this)" id="city" name="city" title="请选择所在城市">
                        <option value="">选择城市</option>
                    </select>
                    <select id="district" name="region" title="请选择所在区县">
                        <option value="">选择区域</option>
                    </select>
                    <input type="text" name="address" id="address" class="input-txt" placeholder="详细地址">
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="sex">性别</label>
                </dt>
                <dd class="opt">
                    <input id="sex" name="age_gender" type="radio" value="0" checked="">保密  &nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="age_gender" type="radio" value="1">男  &nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="age_gender" type="radio" value="2">女
                </dd>
            </dl>

            <div class="bot"><input type="submit" value="确认提交" class="ncap-btn-big ncap-btn-green" id="checkUserUpdate"></div>
        </div>
    </form>
</div>
<script>
    /**
     * 获取城市
     * @param t  省份select对象
     */
    function get_city(t){

        var parent_id = $(t).val();
//        $.get('getRegion',{'level':'2', 'parent_id':parent_id},function(data){
//            if(data){
//
//                v = '<option value="0">选择城市</option>'+ data;
//                $('#city').empty().html(v);
//            }
//        })
//        alert(parent_id)
        if(!parent_id > 0){
            return;
        }
        $('#district').empty().css('display','none');
       $('#twon').empty().css('display','none');
        var url = 'getRegion';

        $.ajax({
            type : "GET",
            url  : url,
            data:{level:2,parent_id: parent_id},
            error: function(request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function(v) {
                v = '<option value="0">选择城市</option>'+ v;
                $('#city').empty().html(v);
            }
        });
    }
    /**
     * 获取地区
     * @param t  城市select对象
     */
    function get_area(t){
        var parent_id = $(t).val();
        if(!parent_id > 0){
            return;
        }
        $('#district').empty().css('display','inline');
        $('#twon').empty().css('display','none');
        var url = 'getRegion';
        $.ajax({
            type : "GET",
            url  : url,
            data:{level:3,parent_id: parent_id},
            error: function(request) {
                alert("服务器繁忙, 请联系管理员!");
                return;
            },
            success: function(v) {
                v = '<option>选择区域</option>'+ v;
                $('#district').empty().html(v);
            }
        });
    }

</script>
<script>
    $('#checkUserUpdate').click(function () {

        var email = $('input[name="agem_email"]').val();
        var mobile = $('input[name="agem_phone"]').val();
        var password = $('input[name="age_password"]').val();
        var error ='';

        if(password == ''){
            error += "密码不能为空\n";
        }
        if(password.length<6 || password.length>16){
            error += "密码长度不正确\n";
        }

        if(!checkEmail(email) && email != ''){
            error += "邮箱地址有误\n";
        }
        if(!checkMobile(mobile) && mobile != ''){
            error += "手机号码填写有误\n";
        }

        if(email == '' && mobile ==''){
            error += "手机和邮箱请至少填一项\n";
        }

        if(error){
            layer.alert(error, {icon: 2});  //alert(error);
            return false;
        }
        return true;


    });

</script>
<script>
    $('#nickname').change(function () {
        var username = $('input[name="age_username"]').val();
        var error ='';
        $.ajax({
            type : 'post',
            url : "{:url('admin/Agents/addAjax')}",
            data : {age_username:username},
            dataType : 'json',
            success : function(data){
                if(data){
                    error+="该账号已存在";
                    layer.alert(error, {icon: 2});  //alert(error);
                    return false;
                }
                return true;
            }
        })

    });

</script>